/*
 * XQRequest.java
 */

package xq.api;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author ThorntonRP
 */
public final class XQRequest {

	private final XQuery xquery;
	private final Map<String, Object> variables;

	public XQRequest(XQuery xquery) {
		this.xquery = xquery;
		this.variables = new HashMap<String, Object>();
		for (XQVariable var : xquery.getExternalVariables()) {
			variables.put(var.getName(), null);
		}
	}

	public XQuery getXQuery() {
		return xquery;
	}

	public void setVariableInput(String name, Object value) {
		if (!variables.containsKey(name)) {
			throw new IllegalArgumentException("No external variable named \"" + name + "\".");
		} else if (value == null) {
			throw new IllegalArgumentException("Variable input value for \"" + name + "\" cannot be null.");
		} else {
			variables.put(name, value);
		}
	}

	public Object getVariableInput(String name) {
		return variables.get(name);
	}
}
